import { Request, Response, NextFunction } from 'express';
// 成功处理中间件
export function handleSuccess(req: Request, res: Response, next: NextFunction) {
  if (res.locals.data) {
    res
      .status(200)
      .json({ code: 200, data: res.locals.data, message: '请求成功' });
  } else {
    next(res.locals.error);
  }
}
export function handleError(
  error: { code: any; message: any },
  req: Request,
  res: Response,
  next: NextFunction,
) {
  res
    .status(error?.code || 500)
    .json({ code: error?.code || 500, message: error.message, data: null });
}
